import java.util.Vector;

import sdljava.SDLException;
import sdljava.SDLMain;
import sdljava.ttf.SDLTTF;


public class Game {
	
	private GameWindow gameWindow;
	private Location current;
	private Vector<Location> locations;
	private CharacterSprite character;
	private Vector<MaterialSprite> materials;
	public enum E {BRICK, WOOD2,  FLATTINROOF,TRIANGLEWOODROOF, 
		STONE, WOOD1, FLATCLAYROOF, WOOD3, METALSTEEPTRIANGLEROOF,
			FLATWOODROOF};
	
	public Game() throws SDLException{
		locations = new Vector<Location>();
		materials = new Vector<MaterialSprite>();
	}
	
	public void populateMVector() throws SDLException{
		ImageData brickImage = new ImageData(1, 0, 167, 167, 0, 0);
		MaterialSprite brick = new MaterialSprite(gameWindow, brickImage, 0, 0, "bitmaps/brick button.bmp");
		brick.setAttributes(0.2, 0.1, "brick", null);
		
		ImageData wood2Image = new ImageData(1, 0, 191, 167, 0, 0);
		MaterialSprite wood2m = new MaterialSprite(gameWindow, wood2Image, 0, 0, "bitmaps/wood button.bmp");
		wood2m.setAttributes(0, 2, "wood", null);
		
		ImageData tinroofImage = new ImageData(1, 0, 290, 167, 0, 0);
		MaterialSprite tinroof = new MaterialSprite(gameWindow, tinroofImage, 0, 0, "bitmaps/tin roof button.bmp");
		tinroof.setAttributes(10, 10, "tin", "flat");
		
		ImageData triangleWoodRoofImage = new ImageData(1, 0, 290, 167, 0, 0);
		MaterialSprite triangleWoodRoof = new MaterialSprite(gameWindow, triangleWoodRoofImage, 0, 0, "bitmaps/wood roof button.bmp");
		triangleWoodRoof.setAttributes(3, 10, "wood", "triangle");
		
		materials.add(brick);
		materials.add(wood2m);
		materials.add(tinroof);
		materials.add(triangleWoodRoof);
	}
	
	public void Init() throws SDLException{
		SDLMain.init(SDLMain.SDL_INIT_EVERYTHING);
		SDLTTF.init();
	}
	
	public void createGameWindow() throws SDLException{
		gameWindow = new GameWindow();
	}
	
	public void createLocationVector() throws SDLException{
		populateVector();
	}
	
	public void showLocation() throws SDLException{
		current.show();
	}
	
	public void clear(){
		SDLMain.quit();
	}
	
	public Location getCurrent(){
		return current;
	}
	
	public Location getNext(){
		if(current!= locations.lastElement()){
			return locations.get(locations.indexOf(current)+1);
		}
		return current;
	}
	
	private void populateVector() throws SDLException{
		StartMenu start = new StartMenu(gameWindow, "bitmaps/title_screen_no_buttons.bmp");
		CharacterSelection selection = new CharacterSelection(gameWindow, "bitmaps/Character Screen_n.bmp");
		Earth earth = new Earth(gameWindow, "bitmaps/grass.bmp");
		MissionDetail missiondetail = new MissionDetail(gameWindow, "bitmaps/mission screen moon.bmp");
		EndingScreens success = new EndingScreens(gameWindow, "bitmaps/succes screen.bmp");
		EndingScreens fail = new EndingScreens(gameWindow, "bitmaps/fail screen.bmp");
		Vector<String> enumerate = new Vector<String>();
		Vector<Integer> Available = new Vector<Integer>();
		enumerate.add("BRICK");
		Available.add(5500);
		Planet moon = new Planet(gameWindow); 
		moon.populateMSVector(materials, Available, enumerate);
		enumerate.removeAllElements();
		enumerate.add("WOOD2");
		Available.removeAllElements();
		Available.add(16);
		moon.populateMSVector(materials, Available, enumerate);
		enumerate.removeAllElements();
		enumerate.add("TRIANGLEWOODROOF");
		enumerate.add("FLATTINROOF");
		Available.removeAllElements();
		Available.add(1);
		Available.add(1);
		moon.populateMSVector(materials, Available, enumerate);		
		moon.populateChildMSVectors();
		moon.getConstruction().getSites().get(0).setAnswers(10.0,10.0,"brick", null);
		moon.getConstruction().getSites().get(1).setAnswers(10.0, 2.0, "wood", null);
		moon.getConstruction().getSites().get(2).setAnswers(0.0,0.0,"tin", "flat");
		locations.add(start);
		locations.add(selection);
		locations.add(earth);
		locations.add(missiondetail);
		locations.add(moon);
		locations.add(success);
		locations.add(fail);
		
		current = locations.firstElement();
	}
	
	public void setLocations(Vector<Location> locations) {
		this.locations = locations;
	}

	public Vector<Location> getLocations() {
		return locations;
	}

	public void setCurrent(Location nextCurrent) {
		// TODO Auto-generated method stub
		this.current = nextCurrent;
	}
	public void initializeConstructionSites(){
	}
}
